package dao

import (
	"advertising/config/redis"
	"advertising/internal/dal"
	"advertising/internal/define"
	"advertising/internal/models"
	"context"
	"time"
)

type PromotionCount struct{}

// Increase 推广计数
func (PromotionCount) Increase(
	promotionID string,
) {
	rdb := redis.NewDB()
	redisCtx, redisCancel := context.WithTimeout(context.Background(), time.Second*3)
	defer redisCancel()
	rdb.Incr(redisCtx, define.RedisPromotionCount+promotionID)
}

// GetName 获取推广名称
func (PromotionCount) Detail(
	ctx context.Context,
	query *dal.Query,
	promotionID string,
) (*models.PromotionCount, error) {
	p := query.PromotionCount
	record, _ := p.WithContext(ctx).Where(p.ID.Eq(promotionID)).Take()
	return record, nil
}
